use std::collections::HashSet;
use std::i32;

struct Solution {}

fn main() {}

impl Solution {
    pub fn minimum_operations(nums: Vec<i32>) -> i32 {
        let mut nums_cp = nums.clone();
        nums_cp.reverse();
        let a = nums_cp.len() % 3;
        let mut idx = if a == 0 { a + 3 } else { a };
        while idx <= nums_cp.len() {
            if HashSet::<i32>::from_iter(nums_cp[0..idx].iter().cloned()).len() < idx {
                break;
            }
            idx += 3;
        }

        if idx > nums_cp.len() {
            return 0;
        }
        ((nums_cp.len() - idx) / 3 + 1) as i32
    }
}